#include "iostream"
#include "string"
#define Max 200
using namespace std;

string storage[Max][3];

void run(){
    int count;
    cin>>count;

    for(int i=0;i<count;i++){
        for(int j=0;j<3;j++){
            cin>>storage[i][j];
        }
    }

    int MaxGrade=-1;
    int MinGrade=101;
    int MaxIndex=-1;
    int MinIndex=-1;
    int tmp;

    for(int i=0;i<count;i++){
        tmp= stoi(storage[i][2]);
        if(tmp>MaxGrade){
            MaxGrade=tmp;
            MaxIndex=i;
        }
        if(tmp<MinGrade){
            MinGrade=tmp;
            MinIndex=i;
        }
    }

    cout<<storage[MaxIndex][0]<<" "<<storage[MaxIndex][1]<<endl;
    cout<<storage[MinIndex][0]<<" "<<storage[MinIndex][1]<<endl;

}

int main(){
    run();
    return 0;
}

//Joe Math990112 89
//Mike CS991301 100
//Mary EE990830 95